﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace DailyStrips.Model.ImageProvideStrategies
{
  


  public class MemoryImageProviderStrategy : FallbackImageProviderStrategy
  {
    private  Dictionary<DateTime, ImageSource> cache;

    public MemoryImageProviderStrategy(IImageProviderStrategy fallbackStrategy)
      :base(fallbackStrategy)
    {
      cache = new Dictionary<DateTime, ImageSource>();
    }

    protected override ImageSource HandleGetImage(DateTime date)
    {
      return cache[date];
    }

    public override bool IsImageAvailable(DateTime date)
    {
      return cache.ContainsKey(date); 
    }

    protected override void HandleFallbackResult(DateTime date, ImageSource result)
    {
      if (!IsImageAvailable(date))
        cache.Add(date, result);
    }
  }
}
